<?php
class BaseAction extends Action {
	public function _initialize() {
	}
	
	/**
	*	组装导航条所需要的数据
	**/
	public function _assembleNavData($scode='',$sdesc='',$sscode='',$ssdesc='',$ssscode='',$sssdesc='',$shelfid='',$shelftitle=''){
		$nav_code['s']=array('id'=>$scode,'desc'=>$sdesc);
		$nav_code['ss']=array('id'=>$sscode,'desc'=>$ssdesc);
		$nav_code['sss']=array('id'=>$ssscode,'desc'=>$sssdesc);
		$nav_code['p']=array('id'=>$shelfid,'desc'=>$shelftitle);
		$this->assign('nav_code', $nav_code);
	}
	
	
	/** 设置cookie中的商品流览纪录变量．并返回当前浏览纪录 **/
	public function visitedShelf2Cookie($shelfid,$limited=5){
			$limited=5;
			if(intval($shelfid)<1)return ;
			//Cookie::delete('tmp_visitedShelfIds');
			$visitedShelfIds 	= Cookie::get('tmp_visitedShelfIds');

			$sids = explode('.',$visitedShelfIds);
			$ifvisited = in_array($shelfid,$sids);
			if(!$ifvisited){
				if(empty($visitedShelfIds)){
						$visitedShelfIds = '.'.$shelfid.'.';
				}else{
						$visitedShelfIds = $visitedShelfIds.$shelfid.'.';
				}
			}
			
			/**判断纪录浏览数据条数**/
			$sids_tmp = explode('.',$visitedShelfIds);
			$len = count($sids_tmp);
			if( $len > ($limited+2) ){
					unset($visitedShelfIds);
					$visitedShelfIds = '.';
					for($i=$len-2 ; $i > ($len-$limited-2) ; $i-- ){
							$visitedShelfIds = '.'.$sids_tmp[$i].$visitedShelfIds;
					}
			}
			Cookie::set('tmp_visitedShelfIds',$visitedShelfIds,60*60*24);
			
			/**
			echo 'visitedShelfIds='.$visitedShelfIds;
			echo '<br>tmp_visitedShelfIds=';
			echo $tmp_visitedShelfIds;
			dump($_COOKIE);
			echo '<br>'.$tmp;
			dump($sids);
			**/
			return $sids;
	}
}